package embedfile

import (
	"embed"
	"encoding/base64"
	"net/http"
)

var (
	DefaultModels *embed.FS
	Template      *embed.FS
	Static        *embed.FS

	LogoBase64 string
)

func SetEmbedFile(fs ...*embed.FS) {
	if len(fs) != 3 {
		return
	}

	DefaultModels = fs[0]
	Template = fs[1]
	Static = fs[2]

	setLogo()
}

func setLogo() {
	file, _ := Static.ReadFile("static/img/logo.png")

	// Determine the content type of the image file
	mimeType := http.DetectContentType(file)

	// Prepend the appropriate URI scheme header depending
	// on the MIME type
	switch mimeType {
	case "image/jpeg":
		LogoBase64 += "data:image/jpeg;base64,"
	case "image/png":
		LogoBase64 += "data:image/png;base64,"
	}

	LogoBase64 += base64.StdEncoding.EncodeToString(file)
}
